home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrecord-1.8.1 / lib / jsprintf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-30  |  2.5 KB  |  122 lines

  1. /* @(#)jsprintf.c    1.12 99/08/30 Copyright 1985 J. Schilling */
  2. /*
  3.  *    Copyright (c) 1985 J. Schilling
  4.  */
  5. /*
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; see the file COPYING.  If not, write to
  18.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <mconfig.h>
  22. #include <stdio.h>
  23. #include <vadefs.h>
  24. #include <standard.h>
  25.  
  26. #define BFSIZ    256
  27.  
  28. typedef struct {
  29.     short    cnt;
  30.     char    *ptr;
  31.     char    buf[BFSIZ];
  32.     int    count;
  33.     FILE    *f;
  34. } *BUF, _BUF;
  35.  
  36. LOCAL    void    _bflush        __PR((BUF));
  37. LOCAL    void    _bput        __PR((char, long));
  38. EXPORT    int    js_fprintf    __PR((FILE *, const char *, ...));
  39. EXPORT    int    js_printf    __PR((const char *, ...));
  40.  
  41. LOCAL void _bflush (bp)
  42.     register BUF    bp;
  43. {
  44.     bp->count += bp->ptr - bp->buf;
  45.     if (filewrite (bp->f, bp->buf, bp->ptr - bp->buf) < 0)
  46.         bp->count = EOF;
  47.     bp->ptr = bp->buf;
  48.     bp->cnt = BFSIZ;
  49. }
  50.  
  51. #ifdef    PROTOTYPES
  52. LOCAL void _bput (char c, long l)
  53. #else
  54. LOCAL void _bput (c, l)
  55.         char    c;
  56.         long    l;
  57. #endif
  58.     register BUF    bp = (BUF)l;
  59.  
  60.     *bp->ptr++ = c;
  61.     if (--bp->cnt <= 0)
  62.         _bflush (bp);
  63. }
  64.  
  65. /* VARARGS2 */
  66. #ifdef    PROTOTYPES
  67. EXPORT int js_printf(const char *form, ...)
  68. #else
  69. EXPORT int js_printf(form, va_alist)
  70.     char    *form;
  71.     va_dcl
  72. #endif
  73. {
  74.     va_list    args;
  75.     _BUF    bb;
  76.  
  77.     bb.ptr = bb.buf;
  78.     bb.cnt = BFSIZ;
  79.     bb.count = 0;
  80.     bb.f = stdout;
  81. #ifdef    PROTOTYPES
  82.     va_start(args, form);
  83. #else
  84.     va_start(args);
  85. #endif
  86.     format(_bput, (long)&bb, form, args);
  87.     va_end(args);
  88.     if (bb.cnt < BFSIZ)
  89.         _bflush (&bb);
  90.     return (bb.count);
  91. }
  92.  
  93. /* VARARGS3 */
  94. #ifdef    PROTOTYPES
  95. EXPORT int js_fprintf(FILE *file, const char *form, ...)
  96. #else
  97. EXPORT int js_fprintf(file, form, va_alist)
  98.     FILE    *file;
  99.     char    *form;
  100.     va_dcl
  101. #endif
  102. {
  103.     va_list    args;
  104.     _BUF    bb;
  105.  
  106.     bb.ptr = bb.buf;
  107.     bb.cnt = BFSIZ;
  108.     bb.count = 0;
  109.     bb.f = file;
  110. #ifdef    PROTOTYPES
  111.     va_start(args, form);
  112. #else
  113.     va_start(args);
  114. #endif
  115.     format(_bput, (long)&bb, form, args);
  116.     va_end(args);
  117.     if (bb.cnt < BFSIZ)
  118.         _bflush (&bb);
  119.     return (bb.count);
  120. }
  121.